<?php
if (get('flash') == 'null')
{
	if (session('enableFlash') == 'null' && session('disableFlash') == 'null')
	{
		//first time
		$flashRD = '<div id="flashDiv"></div>';
	}
	else
	{
		//doNothing();
		$flashRD = '';
	}
}
else
{
	$flashRD = '';
	initiateFlash(get('flash'), 'true');
}

function initiateFlash($getVar, $override)
{
	if (session('enableFlash') == 'null' && session('disableFlash') == 'null')
	{
		flash($getVar);
	}
	else
	{
		if ($override == 'true')
		{
			flash($getVar);
		}
		else
		{
			//doNothing();
		}
	}
}

function flash($status)
{
	if ($status == 'enabled')
	{
		unsetVar('SESSION', 'disableFlash');
		$_SESSION['enableFlash'] = '1';
	}
	else if ($status == 'disabled')
	{
		unsetVar('SESSION', 'enableFlash');
		$_SESSION['disableFlash'] = '1';
	}
	else
	{
		echo '<script>window.location="./home";</script>';
	}
}

function replaceFlashLibrary($file)
{
	/*
	  Flash Module Replacement Library:
	  Holds data that is to be replaced per flash element if no flash player is
	  detected via redirectFlash() function. To create an entry, create an index
	  within the $display array with the same file name (sans extension) with the
	  flash element you are going to be replacing.
	*/
	$display = array();
	$display['homeFlash'] = '
		<div id="flashNone">
				<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get it <a href="http://get.adobe.com/flashplayer/" target="_blank">here</a> for free.
			</div>
	';
	return $display[$file];
}

function embedFlashFile($flashFile, $width, $height, $bgColor)
{
	/*
	  Flash Module Flash Content Wrapper:
	  This is called whenever flash content is needed in order to display the
	  website. This function works with 'replaceFlashLibrary'.
	*/
	
	if ($bgColor != 'transparent')
	{
		$bgColord = 'window';
	}
	else
	{
		$bgColord = 'transparent';
	}
	$gets = $_SERVER['QUERY_STRING'];
	$gets2 = str_replace('&', '_', $gets);
	$placer = str_replace('=', '@', $gets2);
	$noFlash = replaceFlashLibrary($flashFile);
	
	$flash = '
	<div id="'.$flashFile.'Div" >
	<script language="JavaScript" type="text/javascript">
	AC_FL_RunContent(
		\'codebase\', \'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\',
		\'width\', \''.$width.'\',
		\'height\', \''.$height.'\',
		\'src\', \'swf/'.$flashFile.'\',
		\'FlashVars\', \'getvar='.$placer.'\',
		\'quality\', \'high\',
		\'pluginspage\', \'http://www.adobe.com/go/getflashplayer\',
		\'align\', \'middle\',
		\'play\', \'true\',
		\'loop\', \'true\',
		\'scale\', \'showall\',
		\'wmode\', \''.$bgColord.'\',
		\'devicefont\', \'false\',
		\'id\', \''.$flashFile.'\',
		\'bgcolor\', \''.$bgColor.'\',
		\'name\', \''.$flashFile.'\',
		\'menu\', \'true\',
		\'allowFullScreen\', \'false\',
		\'allowScriptAccess\',\'sameDomain\',
		\'movie\', \'swf/'.$flashFile.'\',
		\'salign\', \'\'
		); //end AC code
</script>
<noscript>
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'.$width.'" height="'.$height.'" id="'.$flashFile.'" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="allowFullScreen" value="false" />
	<param name="movie" value="swf/'.$flashFile.'.swf" />
	<param name="quality" value="high" />
	<param name="bgcolor" value="'.$bgColor.'" />
	<param name="FlashVars" value="getvar='.$placer.'">
	
	<embed src="swf/'.$flashFile.'.swf" FlashVars="getvar='.$placer.'" quality="high" bgcolor="'.$bgColor.'" width="'.$width.'" height="'.$height.'" name="'.$flashFile.'" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
	</object>
</noscript>
</div>
	';
	
	if (isset($_SESSION['enableFlash']))
	{
		$display = $flash;
	}
	else
	{
		$display = $noFlash;
	}
	return $display;
}

function redirectFlash()
{
	/*
	  Flash Module Flash Content Detector:
	  Redirects if no flash detected. Check /swf folder if redirection.swf is present.
	*/
	
	if (isset($_SESSION['enableFlash']))
	{
		$display = '';
		//doNothing();
	}
	else
	{
		if (isset($_SESSION['disableFlash']))
		{
			$display = '';
		}
		else
		{
			$gets = $_SERVER['QUERY_STRING'];
			$gets2 = str_replace('&', '_', $gets);
			$placer = str_replace('=', '@', $gets2);
			/* $display = 'redirecting flash'; */
			$display = '
			<div id="popUnder">
			<script language="JavaScript" type="text/javascript">
			AC_FL_RunContent(
				\'codebase\', \'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\',
				\'width\', \'1\',
				\'height\', \'1\',
				\'src\', \'redirection\',
				\'FlashVars\', \'getvar='.$placer.'\',
				\'quality\', \'high\',
				\'pluginspage\', \'http://www.adobe.com/go/getflashplayer\',
				\'align\', \'middle\',
				\'play\', \'true\',
				\'loop\', \'true\',
				\'scale\', \'showall\',
				\'wmode\', \'window\',
				\'devicefont\', \'false\',
				\'id\', \'redirection\',
				\'bgcolor\', \'#ffffff\',
				\'name\', \'redirection\',
				\'menu\', \'true\',
				\'allowFullScreen\', \'false\',
				\'allowScriptAccess\',\'sameDomain\',
				\'movie\', \'redirection\',
				\'salign\', \'\'
				); //end AC code
		</script>
		<noscript>
			<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="1" height="1" id="redirection" align="middle">
			<param name="allowScriptAccess" value="sameDomain" />
			<param name="allowFullScreen" value="false" />
			<param name="movie" value="redirection.swf" />
			<param name="quality" value="high" />
			<param name="bgcolor" value="#ffffff" />
			<param name="FlashVars" value="getvar='.$placer.'">
			
			<embed src="redirection.swf" FlashVars="getvar='.$placer.'" quality="high" bgcolor="#ffffff" width="1" height="1" name="redirection" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
			</object>
		</noscript>
			</div>
		';
		}
		
		
	}
	
		return $display;
}
?>